package com.example.library;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.RelativeLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gaoyeping on 2017/5/9.
 */

public class FaceView3 extends RelativeLayout implements AdapterView.OnItemClickListener {
    private Context mContext;
    private ArrayList<Integer> imgIds;
    private ArrayList<String> tags;
    private GridView grid_view;
    private GridViewAdapter adapter;

    public FaceView3(Context context) {
        super(context);
        this.mContext = context;
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(R.layout.fragment_face_layout, this, true);
        grid_view = (GridView) view.findViewById(R.id.grid_view);
        grid_view.setOnItemClickListener(this);
        addData();
    }

    public FaceView3(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
    }

    private void addData() {
        imgIds = new ArrayList<>();
        imgIds.add(R.drawable.d_dahaqi);
        imgIds.add(R.drawable.d_jiyan);
        imgIds.add(R.drawable.d_shiwang);
        imgIds.add(R.drawable.d_ding);
        imgIds.add(R.drawable.d_yiwen);
        imgIds.add(R.drawable.d_kun);
        imgIds.add(R.drawable.d_ganmao);
        imgIds.add(R.drawable.d_baibai);
        imgIds.add(R.drawable.d_heixian);
        imgIds.add(R.drawable.d_yinxian);
        imgIds.add(R.drawable.d_dalian);
        imgIds.add(R.drawable.d_shayan);
        imgIds.add(R.drawable.d_zhutou);
        imgIds.add(R.drawable.d_xiongmao);
        imgIds.add(R.drawable.d_tuzi);
        imgIds.add(R.drawable.d_jingxi);
        imgIds.add(R.drawable.d_leiben);
        imgIds.add(R.drawable.d_maimeng);
        imgIds.add(R.drawable.d_penxue);
        imgIds.add(R.drawable.d_wunai);
        imgIds.add(R.drawable.d_delete);
        tags = new ArrayList<>();
        tags.add("[打哈气]");
        tags.add("[挤眼]");
        tags.add("[失望]");
        tags.add("[顶]");
        tags.add("[疑问]");
        tags.add("[困]");
        tags.add("[感冒]");
        tags.add("[拜拜]");
        tags.add("[黑线]");
        tags.add("[阴险]");
        tags.add("[打脸]");
        tags.add("[傻眼]");
        tags.add("[猪头]");
        tags.add("[熊猫]");
        tags.add("[兔子]");
        tags.add("[惊喜]");
        tags.add("[泪奔]");
        tags.add("[卖萌]");
        tags.add("[喷血]");
        tags.add("[无爱]");
        tags.add("[del]");
        addAdapter();
    }

    private void addAdapter() {
        adapter = new GridViewAdapter(imgIds, mContext);
        grid_view.setAdapter(adapter);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        XPTextUtils.setExpressionEdit(tags.get(position));
    }
}
